//initialize,execute only once,can use old function fillcontent
$(function() {
	$.ajax({
		type : "POST",
		contentType : "application/json",
		url : "./servlet/Initialize",
		success : function(result) {
			var obj = JSON.parse(result);
			fillcontent(obj);
		}
	});
});

// check per 10 second,only change jieban_person
$(function() {
	setInterval(check, 5000);
	function check() {
		$.ajax({
			type : "POST",
			contentType : "application/json",
			url : "./servlet/CheckData",
			success : function(result) {
				console.log(result);
				var obj = JSON.parse(result);
				fillcontent2(obj);
			}
		});
		var nowdate = new Date();
		var mytime = nowdate.toLocaleTimeString();
		//console.log(mytime);
		if (mytime.startWith("上午00:00:0")) {
			location.reload();
		}
	}
});

function fillcontent(obj) {
	for ( var j = 0; j < obj.length; j++) {
		if (obj[j].dept == '信息管理部') {
			if (obj[j].today == 'false') {
				$("#xinxi").html('<image src="./image/'+obj[j].pid+'.jpg" height="80" width="60"/>'+ obj[j].name);
			} else
				$("#xinxi_jieban").html('<image src="./image/'+obj[j].pid+'.jpg" height="80" width="60"/>'+ obj[j].name);
		} else if (obj[j].dept == '1号值班领导') {
			if (obj[j].today == 'false')
				$("#ichi").html('<image src="./image/'+obj[j].pid+'.jpg" height="80" width="60"/>'+ obj[j].name);
			else
				$("#ichi_jieban").html('<image src="./image/'+obj[j].pid+'.jpg" height="80" width="60"/>'+ obj[j].name);
		} else if (obj[j].dept == '2号总值班长') {
			if (obj[j].today == 'false')
				$("#ni").html('<image src="./image/'+obj[j].pid+'.jpg" height="80" width="60"/>'+ obj[j].name);
			else
				$("#ni_jieban").html('<image src="./image/'+obj[j].pid+'.jpg" height="80" width="60"/>'+ obj[j].name);
		} else if (obj[j].dept == '运行指挥中心') {
			if (obj[j].today == 'false')
				$("#yunxing").html('<image src="./image/'+obj[j].pid+'.jpg" height="80" width="60"/>'+ obj[j].name);
			else
				$("#yunxing_jieban").html('<image src="./image/'+obj[j].pid+'.jpg" height="80" width="60"/>'+ obj[j].name);
		} else if (obj[j].dept == '安质部运标部') {
			if (obj[j].today == 'false')
				$("#anzhi").html('<image src="./image/'+obj[j].pid+'.jpg" height="80" width="60"/>'+ obj[j].name);
			else
				$("#anzhi_jieban").html('<image src="./image/'+obj[j].pid+'.jpg" height="80" width="60"/>'+ obj[j].name);
		} else if (obj[j].dept == '公安分局') {
			if (obj[j].today == 'false')
				$("#gongan").html('<image src="./image/'+obj[j].pid+'.jpg" height="80" width="60"/>'+ obj[j].name);
			else
				$("#gongan_jieban").html('<image src="./image/'+obj[j].pid+'.jpg" height="80" width="60"/>'+ obj[j].name);
		} else if (obj[j].dept == '安保公司') {
			if (obj[j].today == 'false')
				$("#anbao").html('<image src="./image/'+obj[j].pid+'.jpg" height="80" width="60"/>'+ obj[j].name);
			else
				$("#anbao_jieban").html('<image src="./image/'+obj[j].pid+'.jpg" height="80" width="60"/>'+ obj[j].name);
		} else if (obj[j].dept == '机务维修公司') {
			if (obj[j].today == 'false')
				$("#jiwu").html('<image src="./image/'+obj[j].pid+'.jpg" height="80" width="60"/>'+ obj[j].name);
			else
				$("#jiwu_jieban").html('<image src="./image/'+obj[j].pid+'.jpg" height="80" width="60"/>'+ obj[j].name);
		} else if (obj[j].dept == '商务发展公司') {
			if (obj[j].today == 'false')
				$("#shangwu").html('<image src="./image/'+obj[j].pid+'.jpg" height="80" width="60"/>'+ obj[j].name);
			else
				$("#shangwu_jieban").html('<image src="./image/'+obj[j].pid+'.jpg" height="80" width="60"/>'+ obj[j].name);
		} else if (obj[j].dept == '地服公司') {
			if (obj[j].today == 'false')
				$("#difu").html('<image src="./image/'+obj[j].pid+'.jpg" height="80" width="60"/>'+ obj[j].name);
			else
				$("#difu_jieban").html('<image src="./image/'+obj[j].pid+'.jpg" height="80" width="60"/>'+ obj[j].name);
		} else if (obj[j].dept == '物流公司') {
			if (obj[j].today == 'false')
				$("#wuliu").html('<image src="./image/'+obj[j].pid+'.jpg" height="80" width="60"/>'+ obj[j].name);
			else
				$("#wuliu_jieban").html('<image src="./image/'+obj[j].pid+'.jpg" height="80" width="60"/>'+ obj[j].name);
		} else if (obj[j].dept == '急救中心') {
			if (obj[j].today == 'false')
				$("#jijiu").html('<image src="./image/'+obj[j].pid+'.jpg" height="80" width="60"/>'+ obj[j].name);
			else
				$("#jijiu_jieban").html('<image src="./image/'+obj[j].pid+'.jpg" height="80" width="60"/>'+ obj[j].name);
		} else if (obj[j].dept == '飞行区管理部') {
			if (obj[j].today == 'false')
				$("#feixing").html('<image src="./image/'+obj[j].pid+'.jpg" height="80" width="60"/>'+ obj[j].name);
			else
				$("#feixing_jieban").html('<image src="./image/'+obj[j].pid+'.jpg" height="80" width="60"/>'+ obj[j].name);
		} else if (obj[j].dept == '航站楼管理部') {
			if (obj[j].today == 'false')
				$("#hangzhan").html('<image src="./image/'+obj[j].pid+'.jpg" height="80" width="60"/>'+ obj[j].name);
			else
				$("#hangzhan_jieban").html('<image src="./image/'+obj[j].pid+'.jpg" height="80" width="60"/>'+ obj[j].name);
		} else if (obj[j].dept == '动力能源公司') {
			if (obj[j].today == 'false')
				$("#dongli").html('<image src="./image/'+obj[j].pid+'.jpg" height="80" width="60"/>'+ obj[j].name);
			else
				$("#dongli_jieban").html('<image src="./image/'+obj[j].pid+'.jpg" height="80" width="60"/>'+ obj[j].name);
		} else if (obj[j].dept == '工程部') {
			if (obj[j].today == 'false')
				$("#gongcheng").html('<image src="./image/'+obj[j].pid+'.jpg" height="80" width="60"/>'+ obj[j].name);
			else
				$("#gongcheng_jieban").html('<image src="./image/'+obj[j].pid+'.jpg" height="80" width="60"/>'+ obj[j].name);
		} else if (obj[j].dept == '汽运公司') {
			if (obj[j].today == 'false')
				$("#qiyun").html('<image src="./image/'+obj[j].pid+'.jpg" height="80" width="60"/>'+ obj[j].name);
			else
				$("#qiyun_jieban").html('<image src="./image/'+obj[j].pid+'.jpg" height="80" width="60"/>'+ obj[j].name);
		} else if (obj[j].dept == '停车场公司') {
			if (obj[j].today == 'false')
				$("#tingche").html('<image src="./image/'+obj[j].pid+'.jpg" height="80" width="60"/>'+ obj[j].name);
			else
				$("#tingche_jieban").html('<image src="./image/'+obj[j].pid+'.jpg" height="80" width="60"/>'+ obj[j].name);
		} else if (obj[j].dept == '实业公司') {
			if (obj[j].today == 'false')
				$("#shiye").html('<image src="./image/'+obj[j].pid+'.jpg" height="80" width="60"/>'+ obj[j].name);
			else
				$("#shiye_jieban").html('<image src="./image/'+obj[j].pid+'.jpg" height="80" width="60"/>'+ obj[j].name);
		} else if (obj[j].dept == '凯亚公司') {
			if (obj[j].today == 'false')
				$("#kaiya").html('<image src="./image/'+obj[j].pid+'.jpg" height="80" width="60"/>'+ obj[j].name);
			else
				$("#kaiya_jieban").html('<image src="./image/'+obj[j].pid+'.jpg" height="80" width="60"/>'+ obj[j].name);
		}
	}
};

//refresh
function fillcontent2(obj) {
	for ( var j = 0; j < obj.length; j++) {
		if (obj[j].dept == '信息管理部') {
			$("#xinxi_jieban").html('<image src="./image/'+obj[j].id+'.jpg" height="80" width="60"/>'+ obj[j].name);
		} else if (obj[j].dept == '1号值班领导') {
			$("#ichi_jieban").html('<image src="./image/'+obj[j].id+'.jpg" height="80" width="60"/>'+ obj[j].name);
		} else if (obj[j].dept == '2号总值班长') {
			$("#ni_jieban").html('<image src="./image/'+obj[j].id+'.jpg" height="80" width="60"/>'+ obj[j].name);
		} else if (obj[j].dept == '运行指挥中心') {
			$("#yunxing_jieban").html('<image src="./image/'+obj[j].id+'.jpg" height="80" width="60"/>'+ obj[j].name);
		} else if (obj[j].dept == '安质部运标部') {
			$("#anzhi_jieban").html('<image src="./image/'+obj[j].id+'.jpg" height="80" width="60"/>'+ obj[j].name);
		} else if (obj[j].dept == '公安分局') {
			$("#gongan_jieban").html('<image src="./image/'+obj[j].id+'.jpg" height="80" width="60"/>'+ obj[j].name);
		} else if (obj[j].dept == '安保公司') {
			$("#anbao_jieban").html('<image src="./image/'+obj[j].id+'.jpg" height="80" width="60"/>'+ obj[j].name);
		} else if (obj[j].dept == '机务维修公司') {
			$("#jiwu_jieban").html('<image src="./image/'+obj[j].id+'.jpg" height="80" width="60"/>'+ obj[j].name);
		} else if (obj[j].dept == '商务发展公司') {
			$("#shangwu_jieban").html('<image src="./image/'+obj[j].id+'.jpg" height="80" width="60"/>'+ obj[j].name);
		} else if (obj[j].dept == '地服公司') {
			$("#difu_jieban").html('<image src="./image/'+obj[j].id+'.jpg" height="80" width="60"/>'+ obj[j].name);
		} else if (obj[j].dept == '物流公司') {
			$("#wuliu_jieban").html('<image src="./image/'+obj[j].id+'.jpg" height="80" width="60"/>'+ obj[j].name);
		} else if (obj[j].dept == '急救中心') {
			$("#jijiu_jieban").html('<image src="./image/'+obj[j].id+'.jpg" height="80" width="60"/>'+ obj[j].name);
		} else if (obj[j].dept == '飞行区管理部') {
			$("#feixing_jieban").html('<image src="./image/'+obj[j].id+'.jpg" height="80" width="60"/>'+ obj[j].name);
		} else if (obj[j].dept == '航站楼管理部') {
			$("#hangzhan_jieban").html('<image src="./image/'+obj[j].id+'.jpg" height="80" width="60"/>'+ obj[j].name);
		} else if (obj[j].dept == '动力能源公司') {
			$("#dongli_jieban").html('<image src="./image/'+obj[j].id+'.jpg" height="80" width="60"/>'+ obj[j].name);
		} else if (obj[j].dept == '工程部') {
			$("#gongcheng_jieban").html('<image src="./image/'+obj[j].id+'.jpg" height="80" width="60"/>'+ obj[j].name);
		} else if (obj[j].dept == '汽运公司') {
			$("#qiyun_jieban").html('<image src="./image/'+obj[j].id+'.jpg" height="80" width="60"/>'+ obj[j].name);
		} else if (obj[j].dept == '停车场公司') {
			$("#tingche_jieban").html('<image src="./image/'+obj[j].id+'.jpg" height="80" width="60"/>'+ obj[j].name);
		} else if (obj[j].dept == '实业公司') {
			$("#shiye_jieban").html('<image src="./image/'+obj[j].id+'.jpg" height="80" width="60"/>'+ obj[j].name);
		} else if (obj[j].dept == '凯亚公司') {
			$("#kaiya_jieban").html('<image src="./image/'+obj[j].id+'.jpg" height="80" width="60"/>'+ obj[j].name);
		}

	}
};

String.prototype.startWith = function(str) {
	if (str == null || str == "" || this.length == 0
			|| str.length > this.length)
		return false;
	if (this.substr(0, str.length) == str)
		return true;
	else
		return false;
	return true;
};
